﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using One2Team.EasyScrum.UI.Web.Models;

namespace One2Team.EasyScrum.UI.Web.Controllers
{
    public class CraController : Controller
    {
        private easyscrumEntities db = new easyscrumEntities();

        //
        // GET: /Cra/

        public ActionResult Index()
        {
            var cra = db.cra.Include(c => c.user);
            return View(cra.ToList());
        }

        //
        // GET: /Cra/Details/5

        public ActionResult Details(int id = 0)
        {
            cra cra = db.cra.Find(id);
            if (cra == null)
            {
                return HttpNotFound();
            }
            return View(cra);
        }

        //
        // GET: /Cra/Create

        public ActionResult Create()
        {
            ViewBag.id_user = new SelectList(db.user, "id", "username");
            return View();
        }

        //
        // POST: /Cra/Create

        [HttpPost]
        public ActionResult Create(cra cra)
        {
            if (ModelState.IsValid)
            {
                db.cra.Add(cra);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.id_user = new SelectList(db.user, "id", "username", cra.id_user);
            return View(cra);
        }

        //
        // GET: /Cra/Edit/5

        public ActionResult Edit(int id = 0)
        {
            cra cra = db.cra.Find(id);
            if (cra == null)
            {
                return HttpNotFound();
            }
            ViewBag.id_user = new SelectList(db.user, "id", "username", cra.id_user);
            return View(cra);
        }

        //
        // POST: /Cra/Edit/5

        [HttpPost]
        public ActionResult Edit(cra cra)
        {
            if (ModelState.IsValid)
            {
                db.Entry(cra).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.id_user = new SelectList(db.user, "id", "username", cra.id_user);
            return View(cra);
        }

        //
        // GET: /Cra/Delete/5

        public ActionResult Delete(int id = 0)
        {
            cra cra = db.cra.Find(id);
            if (cra == null)
            {
                return HttpNotFound();
            }
            return View(cra);
        }

        //
        // POST: /Cra/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            cra cra = db.cra.Find(id);
            db.cra.Remove(cra);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}